二叉树的建立在前面已经实现,现在只写子函数
public bitreeNode searchNode(bitreeNode t,Object x){
if(t!=null){
if(t.getdata().equals(x)) //对根节点进行判断
return t;
else{
bitreeNode lresult=searchNode(t.getlchild(),x); //查找左子树
//若在左子树中查找到值为x的结点,则返回该结点;否则,在右子树中查找该结点并返回结果
return lresult!=null?lresult:searchNode(t.getrchild(),x);
}
}
return null;
}
//计算二叉树中结点个数
public int countNode(bitreeNode t){
//采用先根遍历的方式对二叉树进行遍历,计算结点个数
int count=0;
if(t!=null){
count++; //根结点加1
count=count+countNode(t.getlchild()); //加上左子树结点数
count=count+countNode(t.getrchild()); //加上右子树结点数
}
return count;
}
public int countNode1(bitreeNode t){
//采用层次遍历对二叉树进行遍历
int count=0;
if(t!=null){
Linkqueue l=new Linkqueue(); //构造队列
l.offer(t); //根节点入队
while(!l.is